# -*- coding: utf-8 -*-
 ##############################################
 ##                                            ##
 ##                Punto de Venta               ##
 ##                                             ##
 ##                                             ##
 ##              from Basiq Series              ##
 ##            by Críptidos Digitales           ##
 ##                 GPL (c)2008                 ##
  ##                                            ##
    ##############################################

"""
"""

from PyQt4 import QtCore, QtGui

import puntoVenta_ui

from cdWidgets import cdSlideFrame

import ventas





class Controller():

    def __init__(self):
        # print 'puntoVenta.Controller.__init__()'
        ventas.session = session
        ventas.app = app

        self.controllers = []
        salesController = ventas.Controller()
        self.controllers.append(salesController)

    def initDb(self):
        ventas.model.initDb()


    def initForm(self):
        print 'puntoVenta.Controller.initForm()'

        session.mainForm.ui.puntoVenta = Forma(session.mainForm.ui.baseFrame, owner=session.mainForm)
        session.mainForm.slide.addWidget(session.mainForm.ui.puntoVenta)
        session.mainForm.ui.puntoVenta.ui.title.hide()

        ## Tool Menu
        session.mainForm.ui.puntoVentaTO = QtGui.QToolButton(session.mainForm.ui.sectionsFR)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(session.mainForm.ui.puntoVentaTO.sizePolicy().hasHeightForWidth())
        session.mainForm.ui.puntoVentaTO.setSizePolicy(sizePolicy)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("imagenes/User.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        session.mainForm.ui.puntoVentaTO.setIcon(icon)
        session.mainForm.ui.puntoVentaTO.setIconSize(QtCore.QSize(32, 32))
        session.mainForm.ui.puntoVentaTO.setToolTip(u'Punto de Venta\nF5')
        session.mainForm.ui.puntoVentaTO.setShortcut("F5")
        session.mainForm.ui.puntoVentaTO.setAutoRaise(True)

        session.mainForm.ui.sectionsLY.insertWidget(0, session.mainForm.ui.puntoVentaTO)
        session.mainForm.ui.puntoVentaAC = QtGui.QAction(icon, u"", session.mainForm)
        session.mainForm.ui.puntoVentaAC.setCheckable(False)
        session.mainForm.ui.puntoVentaAC.setIconText(u"")
        session.mainForm.connect(session.mainForm.ui.puntoVentaAC, QtCore.SIGNAL("triggered()"), session.mainForm.showPuntoVenta)

        session.mainForm.ui.puntoVentaTO.setDefaultAction(session.mainForm.ui.puntoVentaAC)


        ## Ventas
        session.mainForm.ui.puntoVenta.ui.ventas = ventas.getForm(owner=session.mainForm, mode='captura')

        session.mainForm.ui.puntoVenta.ui.tabWidget.addTab(session.mainForm.ui.puntoVenta.ui.ventas, u"&VENTA")

        if session.mainForm.ui.puntoVenta.ui.tabWidget.count() == 1:
            session.mainForm.ui.puntoVenta.ui.tabWidget.tabBar().hide()







class Forma(QtGui.QFrame):

    def __init__(self, *args, **kwds):

        if kwds.has_key('content'):
            self.__content = kwds.pop('content')
        else:
            self.__content = None

        if kwds.has_key('owner'):
            self.__owner = kwds.pop('owner')
        else:
            self.__owner = None

        QtGui.QFrame.__init__(self, *args)

        self.ui = puntoVenta_ui.Ui_Form()
        self.ui.setupUi(self)

        self.ui.tabWidget.clear()

        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(9*app.fontZoom)

        self.ui.tabWidget.clear()
        self.ui.tabWidget.setFont(font)


    def addProduct(self):
        self.owner.emit(QtCore.SIGNAL('addProduct()'))

    @property
    def owner(self):
        return self.__owner


